1. Field of the Invention
The present invention relates to a compiler, and more particularly, to a Just In Time (JIT) compiler for Java (Java is a trademark of Sun Microsystems).
2. Description of the Related Art
The Java programming language has become ubiquitous over the last few years, due to the propagation of the Internet and its applicability to Internet programming. This is due to the characteristics of Java, especially the characteristics of Java byte code. As illustrated in FIG. 1, a server computer 1 compiles Java source code 10 into Java byte code 14. Java byte code, which can also be thought of as the executable code which comprises a Java program or application or applet, is not dependent on or tied to any specific operating system (OS) (such as Windows, OS/2 or Solaris) or computer platform (such as Intel, PowerPC, or RISC), thus the byte code 14 is not dependant on an OS 53 or hardware/CPU 55 in a client computer 5. (Windows is a trademark of Microsoft Corporation, OS/2 and Power PC are trademarks of IBM, and Solaris is a trademark of Sun Microsystems.) Thus, the byte code 14 can be executed by a variety of client computers connected to a network 3. The client computers can have a variety of hardware and OS configurations.
On the other hand, the Java byte code 14 must be interpreted at execution by the executing client computer. Interpreting code is a relatively slow process compared to executing compiled code (such as that found in C or C++ applications), and has proven to be a stumbling block in the acceptance of Java. The client computers may be workstations, personal computers, or network computers or similar devices, such as home-use information processors, that have small memory capacities or are not equipped with auxiliary storage devices, such as hard disks.
In the Java environment, Java byte code is executed by a client computer by a Java virtual machine which is present on the client computer. As illustrated in FIG. 1, the byte code 14 is provided to a Java virtual machine (Java VM) 52, which is provided for a WWW (World Wide Web) browser in the client computer 5. A Java interpreter 54 and a Java JIT compiler 56 are employed when the CPU (hardware 55) actually executes the byte code 14.
When executing the byte code 14, the interpreter 54 translates the byte code 14 and calls and executes an execution routine that is prepared for each instruction. Using an interpreter provides some advantages. First, execution of the byte code 14 can be initiated immediately, as soon as it is read. Second, as the amount of byte code involved is generally small, only a small memory capacity is required for the execution. A major disadvantage with the use of an interpreter is low execution speed. Low execution speed is the result of the following problems, which, arise because the byte code is decoded just before it is executed. First, since Java byte code is provided in a format having variable lengths, optimization by multiple prefetches is difficult for the CPU to perform. Second, rule-based optimization is difficult to provide for frequently detected byte code. When a complicated rule is employed or when many rules are employed, a relatively large amount of time is required to detect a byte code sequence for which the rule can be applied. Thus, rule-based optimization is not practical. Third, the reading of parameters can take place only at the head of the execution routine, and thus the processing can not be initiated immediately. Fourth, since a decoding loop exists, the processing time for the decoding loop is added to the processing time for the entire byte code 14. Therefore, the processing speed can not be enhanced so that it exceeds the decoding loop processing speed.
To obviate these shortcomings, a number of solutions have been attempted. One involves the use of a "just-in-time" compiler. As illustrated in FIG. 1, the JIT compiler 56 translates the byte code 14 into machine code in advance of or immediately before its execution, and executes it. The advantage of this method is that since the compiler technique is employed to optimize the machine code, the execution speed for the translated code is high. However, a conventional optimizing compiler requires more memory and greater CPU power than does an interpreter.
Another performance enhancement technique involves using threaded code. Using this technique, the byte code 14 is converted into a subroutine call, which is then executed. The threaded code is a pair of (1) a subroutine, which is prepared for each byte code to process the corresponding byte code, and (2) machine code, which sets a parameter and issues a subroutine call according to the byte code. The threaded code is obtained by compiling the byte code into machine code components, each of which has a minimum size. Executing the threaded code is faster than interpreting byte code and requires fewer resources than a conventional optimizing compiler. However, there are a number of drawbacks involved with using threaded code. First, to execute Java byte codes with, for example, a 32-bit RISC CPU, the average amount of memory occupied by converted parameter sets and call instructions is four times as large as that occupied by the original byte code. Second, before rule-based optimization can be applied for a frequently detected byte code sequence, the program structure must be analyzed to confirm that the byte code sequence does not extend over a plurality of basic blocks, because then the byte code sequence overhead may offset the effect of the optimization. Third, since intermediate code is also machine code, an execution routine that was previously executed may be expelled from an instruction cache.
However, no Java byte code compiler has been developed that can be incorporated in network computers and home-use information processors, and that can perform high-speed processing while requiring only a few resources.